package com.taldh.objenesis;

import org.springframework.objenesis.Objenesis;
import org.springframework.objenesis.ObjenesisStd;

public class MainTest {

    public static void main(String[] args) throws Exception {
        Objenesis objenesis = new ObjenesisStd();
        // 它竟然创建成功了
        MyDemo myDemo = objenesis.newInstance(MyDemo.class);
        System.out.println(myDemo); //com.fsx.maintest.MyDemo@1f32e575
        System.out.println(myDemo.code); //null  特别注意：这里是null，而不是10

        // 若直接这样创建 就报错 java.lang.InstantiationException: com.fsx.maintest.MyDemo
        System.out.println(MyDemo.class.newInstance());
    }
}

class MyDemo {
    public String code = "10";

    public MyDemo(String code) {
        System.out.println("11111");
        this.code = code;
        System.out.println("22222");
    }
}
